﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Unity.Errors.types
{
    public class TErrorInfo
    {
        //ctors
        public TErrorInfo()
        {
            _Namespace = String.Empty;
            _Class = String.Empty;
            _Method = String.Empty;
        }
        public TErrorInfo(string namespaceName, string className, string methodName)
        {
            _Namespace = namespaceName;
            _Class = className;
            _Method = methodName;
        }
        public TErrorInfo(Type srcType, string methodName)
        {
            _Namespace = srcType.Namespace;
            _Class = srcType.Name;
            try
            {
                MethodInfo[] arr = srcType.GetMethods();
                MethodInfo mi = srcType.GetMethod(methodName);
                string paramList = "";
                ParameterInfo[] piArr = mi.GetParameters();
                int limit = piArr.Length;
                for (int i = 0; i < limit; i++)
                {
                    paramList += 
                        String.Format("{0} {1}, "
                        ,piArr[i].ParameterType.Name
                        , piArr[i].Name) ;
                }
                paramList = paramList.TrimEnd(',', ' ');
                _Method = 
                    String.Format("{0} {1}({2})", mi.ReturnParameter.Name, mi.Name, paramList);
            }
            catch { _Method = methodName; }
        }
        //Properties:
        private string _Namespace;
        public string Namespace
        {
            get { return _Namespace; }
            set { _Namespace = value; }
        }

        private string _Class;
        public string Class
        {
            get { return _Class; }
            set { _Class = value; }
        }

        private string _Method;
        public string Method
        {
            get { return _Method; }
            set { _Method = value; }
        }

        //Overrids:
        public override string ToString()
        {
            return String.Format("[Namespace:]{0}\n\t[Class:]{1}\n\t[Method:]{2}\n", _Namespace, _Class, _Method);
        }
    }
}
